<template>
    <div class="product-detail">
      <s-header :title="'商品详情'"></s-header>
      <!-- 商品内容 -->
      <div class="detail-content">
        <div class="detail-swipe-wrap">
          <van-swipe
            class="my-swipe"
            indicator-color="#1baeae"
          >
          <van-swipe-item
					>
          <img :src="detail.image" alt="" >
        </van-swipe-item>
          </van-swipe>
        </div>
        <div class="product-info">
          <div class="product-title">
              {{detail.goods_name}}
          </div>
          <div class="product-desc">免邮费 顺丰快递</div>
          <div class="product-price">
            <span>¥{{ detail.selling_price }}</span>
          </div>
        </div>
        <!-- 商品介绍 -->
        <div class="product-intro">
          <ul>
            <li>概述</li>
            <li>参数</li>
            <li>安装服务</li>
            <li>常见问题</li>
          </ul>
          <div
					class="product-content"
					v-html="detail.introduce"
				></div>
        </div>
      </div>
      <van-action-bar>
  <van-action-bar-icon icon="chat-o" text="客服" />
  <van-action-bar-icon icon="cart-o" text="购物车" @click="goTo()"/>
  <van-action-bar-button color="#1cacac" type="warning" text="加入购物车" @click="addCartResult"/>
  <van-action-bar-button color="#1cacac" type="danger" text="立即购买" 	@click="goToCart"/>
</van-action-bar>
  
    </div>
  </template>
  
  <script setup lang="ts">
  import sHeader from "../components/SimpleHeader.vue";
  import { useRoute,useRouter } from 'vue-router';
  import {onMounted, ref,reactive} from 'vue'
  import { getDetail } from "@/service/good";
  import {addCart} from '../service/cart'
  import { Toast } from "vant";
  const route = useRoute()
  const router = useRouter()
  let detail = reactive({
    category:'',
    goods_name:'',
    count:1,
    detail_goods:'',
    goods_id:'',
    image:'',
    introduce:'',
    original_price:21,
    selling_price:'',
    tag:''
  })
   onMounted(async()=>{
      const {id} = route.params
      console.log(route.params);
      console.log(id);
      const {data} = await getDetail({
      "goods_id":Number(id) 
      })
     detail.image = data.image
     detail.category = data.category
     detail.goods_name = data.goods_name
     detail.count = data.count
     detail.detail_goods = data.detail_goods
     detail.goods_id = data.goods_id
     detail.introduce = data.introduce
     detail.original_price = data.original_price
     detail.selling_price = data.selling_price
     detail.tag = data.tag
     console.log(detail);
     console.log(detail.goods_name);
  })
  // 这是点击回退到首页功能
  function goBack() {
    router.go(-1)
  }
  // goTo是去购物车界面
  function goTo() {
    router.push({ path: "/cart" });
  }
  // 加入购物车
  async function addCartResult(){
    const { data, code } = await addCart({
				"goods_id": detail.goods_id,
			});
   if(code === 1000) Toast.success("添加成功");
   console.log(code,'@@@@@@@@@@'); 
  }
 


  // // 立即购买
  async function goToCart() {
    const { data, code } = await addCart({
				"goods_id": detail.goods_id,
			});
    router.push({ path: "/cart" });
  }
  </script>
  
  <style lang="less" scoped>
  @import "../common/style/mixin.less";
  .product-detail {
      .detail-header {
          position: fixed;
          top: 0;
          left: 0;
          z-index: 10000;
          .fj();
          .wh(100%, 44px);
          line-height: 44px;
          padding: 0 10px;
          .boxSizing();
          color: #252525;
          background: #fff;
          border-bottom: 1px solid #dcdcdc;
          .product-name {
              font-size: 14px;
          }
      }
      .detail-content {
          margin-top: 44px;
          .detail-swipe-wrap {
              .my-swipe .van-swipe-item {
                  img {
                      width: 100%;
                      // height: 300px;
                  }
              }
          }
          .product-info {
              padding: 0 10px;
              .product-title {
                  font-size: 18px;
                  text-align: left;
                  color: #333;
              }
              .product-desc {
                  font-size: 14px;
                  text-align: left;
                  color: #999;
                  padding: 5px 0;
              }
              .product-price {
                  .fj();
                  span:nth-child(1) {
                      color: #f63515;
                      font-size: 22px;
                  }
                  span:nth-child(2) {
                      color: #999;
                      font-size: 16px;
                  }
              }
          }
          .product-intro {
              width: 100%;
              ul {
                  .fj();
                  width: 100%;
                  margin: 10px 0;
                  li {
                      flex: 1;
                      padding: 5px 0;
                      text-align: center;
                      font-size: 15px;
                      border-right: 1px solid #999;
                      box-sizing: border-box;
                      &:last-child {
                          border-right: none;
                      }
                  }
              }
              .product-content {
                  padding: 0 20px;
                  img {
                      width: 100%;
                  }
              }
          }
      }
      .van-goods-action-button--warning {
          background: linear-gradient(to right, #6bd8d8, @primary);
      }
      .van-goods-action-button--danger {
          background: linear-gradient(to right, #0dc3c3, #098888);
      }
  }
  </style>